﻿@using EasyCourse.Model;
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>精品课程管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">
                @pageInfo.CourseName<br>
                <small>广州中医药大学康复治疗微课程网络学习平台</small>
            </h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 0)
    <div class="container mainwrap">
        <div class="row">
            @Html.Partial("~/Views/Share/PublicCourseOtherInfoMenu.cshtml", this.ViewData)
            <div class="col-md-10">
                <div class="panel panel-default mainwrap-part">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <ol class="breadcrumb">
                                <li>精品课程管理</li>
                                <li id="currentInfo" class="active">@ViewData["TypeName"]</li>
                            </ol>
                        </h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <form class="form-horizontal" role="form">
                                <div class="form-group">
                                    <div class="col-sm-3">
                                        <input type="text" class="ml15 form-control input-md" id="titleSearchTxt" placeholder="请输入栏目名称">
                                    </div>
                                    <div class=" col-sm-2">
                                        <button type="button" onclick="getList(1);" class="btn btn-success btn-md"><span class="glyphicon glyphicon-search"></span>查询</button>
                                    </div>
                                    <div class="col-sm-3">
                                        <input type="text" class="ml15 form-control input-md" id="titleAddTxt" placeholder="请输入栏目名称">
                                    </div>
                                    <div class=" col-sm-4">
                                        <button type="button" onclick="addInfo();" class="btn btn-success btn-md"><span class="glyphicon glyphicon-plus"></span>添加栏目</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="row">
                            <table class="table table-bordered tb1 table-striped table-hover">
                                <thead>
                                    <tr>
                                        <th width="50%">栏目名称</th>
                                        <th width="15%">创建时间</th>
                                        <th width="10%">是否停用</th>
                                        <th width="25%">操作</th>
                                    </tr>
                                </thead>
                                <tbody id="tbody">
                                </tbody>
                            </table>
                        </div>
                        <div class="row clearfix well d-page">
                            <div id="PagInfo" class="pull-left sum">
                            </div>
                            <div class="clearfix pull-right">
                                <ul id="PageTool" class="pagination">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 更改栏目名称的弹框 -->
    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">修改栏目名称</h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="mId"  />
                    <div class="form-group">
                        <label for="JcGrpName">栏目名称：</label>
                        <input type="text" class="form-control" id="mTitle" placeholder="请输入栏目名称">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" id="JcSubmit" class="btn btn-info">确认修改</button>
                </div>
            </div>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")
    <script type="text/javascript">
        var tbody = $("#tbody");
        var _courseId = "@ViewData["CourseId"]";
        var options = false;
        var _state = false;
        function getList(pageNo) {

            $("#PagInfo").html("");
            $("#PageTool").html("");

            var _typeCode = $("#courseInfoList li.active").attr("id");
            var _title = $("#titleSearchTxt").val();
            $.easyPost("/CourseOtherInfo/GetCourseOtherInfoList", { "PageNO": pageNo, "PageSize": "10", "CourseId": _courseId, "TypeCode": _typeCode, "IsMenu": true, "Title": _title },
               function (data) {
                   if (!data.result) {
                       showTips.open(data.message);
                       return;
                   }
                   var _html = '';
                   if (data.rows.length > 0) {
                       $(".d-page").show();

                       var _row = data.rows,
                           _rowL = _row.length;
                       options = {
                           totalPages: data.totalPage,
                           total: data.total,
                           currentPage: pageNo,
                           onPageClicked: function (event, originalEvent, type, page) {
                               getList(page);
                           }
                       }
                       initialPaginator(options, "PageTool", "PagInfo");

                       for (var i = 0; i < _rowL; i++) {
                           var item = _row[i];
                           var _date = item.CreateTime.toString().replace(/\//g, "");
                           var time = eval('new ' + _date);
                           var status;
                           if (item.Status) {
                               status = '是';
                           }
                           else {
                               status = '否';
                           }
                           _html += "<tr>";
                           _html += "<td>" + item.Title + "</td>";
                           _html += "<td>" + time.format('yyyy-MM-dd') + "</td>";
                           _html += "<td>" + status + "</td>";
                           _html += "<td>";
                           _html += "<a href='javascript:void(0)' onclick='statusChange(\"" + item.Id + "\")' class='operate'><span class='glyphicon glyphicon-stop'></span> " + (item.Status ? "启用" : "停用") + "</a>";
                           _html += "<a href='javascript:void(0)' class='operate aEdit'><span class='glyphicon glyphicon-pencil'></span> 编辑<input type='hidden' name='editId' value='" + item.Id + "'/></a>";
                           _html += "<a href='/CourseOtherInfo/CourseOtherInfoContentList?CourseId=" + _courseId + "&CourseOtherInfoId=" + item.Id + "' class='operate'><span class='glyphicon glyphicon-briefcase'></span> 内容管理</a>";
                           _html += "</td>";
                           _html += "</tr>";
                       }
                   }
                   else {
                       _html = "<tr><td colspan='4' align='center'>暂无内容!</tr>";
                       $(".d-page").hide();
                   }
                   tbody.html(_html);
               }, "json");
        }


        if (!!window.location.hash) {
            var _hash = window.location.hash.substr(1);
            getList(_hash);
        } else {
            getList(1);
        }


        $("#tbody").delegate(".aEdit", "click", function () {
            $("#editModal").modal("show");
            var _id = $(this).find("input").val();
            var _title = $(this).parent().siblings(0).html();

            $("#mId").val(_id);
            $("#mTitle").val(_title); 
        });
        

        var t = true;
        $("#JcSubmit").click(function () {
            var url = "@Url.Action("CourseOtherInfoEdit", "CourseOtherInfo")";
            var options = {
                type: 'POST',
                data: {"Id":$("#mId").val(),"Title":$("#mTitle").val()},
                url: url,
                async: false,
                cache: false,
                success: function (data) {
                    if (data.result) {
                        $("#editModal").modal("hide");
                        if (!!window.location.hash) {
                            var _hash = window.location.hash.substr(1);
                            getList(_hash);
                        } else {
                            getList(1);
                        }
                    }
                    else {
                        showTips.open(data.message);  
                    }
                }

            }
            if (t) {
                t = false;
                $.ajax(options);
                t = true;
            }
        });


        function addInfo() {
            var _title = $("#titleAddTxt").val();
            var _typeCode = $("#courseInfoList li.active").attr("id");
            $.easyPost("/CourseOtherInfo/CourseOtherInfoAdd", { "Title": _title, "CourseId": _courseId, "TypeCode": _typeCode, "IsMenu": true },
              function (data) {
                  if (!data.result) {
                      showTips.open(data.message);
                      return;
                  }
                  showTips.open("添加成功");
                  $("#titleAddTxt").val("");
                  getList(1);
              }, "json");
        }


        function statusChange(id) {
            $.easyPost("/CourseOtherInfo/CourseOtherInfoStatusChange", { "Id": id },
              function (data) {
                  if (!data.result) {
                      showTips.open(data.message);
                      return;
                  }
                  if (!!window.location.hash) {
                      var _hash = window.location.hash.substr(1);
                      getList(_hash);
                  } else {
                      getList(1);
                  }
              }, "json");
        }






    </script>
</body>
</html>


